package com.feng.sprider;



/**
 * 运行
 * @author feng
 *
 */
public class Start {
	
	ImgUrlQuene imgUrl = new ImgUrlQuene();
	UrlQuene urlQuene = new UrlQuene();
	VisitedUrlQuene visitedUrl = new VisitedUrlQuene();
	
	Get get = new Get(urlQuene, visitedUrl, imgUrl);
	
	/**
	 * 开启线程
	 * @throws InterruptedException 
	 */
	public void openThread() throws InterruptedException{
		
		Threads gets = new Threads(urlQuene, visitedUrl, imgUrl);
		
		Thread t = new Thread(gets);
		
		t.start();
		
		t.join();
		
	}
	
	
	/**
	 * 开启下载
	 * @param args
	 */
	public void beginDown(String homePage){

		// 开启
		
		Down download = new Down();
		
		visitedUrl.addUrl(homePage);
		
		//开始页面
		get.getUrls(homePage);
		get.getImgUrls(homePage);
		
		
		
		//	开启线程
		try {
			
			openThread();
			
		} catch (InterruptedException e) {
			System.out.println("error");
		}
		
		
/*		while(imgUrl.getLength()>0){
			
			System.out.println("剩于图片："+imgUrl.getLength());
			System.out.println("剩余链接："+urlQuene.getLength());
			
			String url = imgUrl.getUrl();
			
			System.out.println("正在下载"+url);
			
			//test
//			download.downImg(url);
			//放入已访问队列
			//移出
			visitedUrl.addUrl(url);
			imgUrl.removeUrl(url);
		}*/
	
	}
	public static void main(String[] args) {
		Start start = new Start();
		
		start.beginDown("http://www.nationalgeographic.com.cn/");
		
		System.out.println("Done ! ");
	}

}
